<?php
	require("includes/basic.php");
	if(!isset($_SESSION['uid']))
	{
		header("location:authorise.php");
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
	<HEAD>
		<TITLE> :: <?php echo $appName?> :: </TITLE>
		<link rel='stylesheet' type='text/css' href='style/admin.css'>		
		<script type='text/javascript' src='js/jquery-latest.js'></script>
		<script type="text/javascript">
$(document).ready(function()
{
	$("#addphase").click(function()
	{
		
		var id=$("#phaseid").val();
		var q=$("#projctid").val();	
		var pm=$("#proman").val();	
		var dataString = 'id='+ id + '&q='+ q + '&pm=' + pm;
		if(id == 0)
		{
			alert("Select Phase");
		}
		else
		{
			$.ajax
			({
				type: "POST",
				url: "phase.php",
				data: dataString,
				cache: false,
				success: function(html)
				{
				$("#phases").html(html);
				} 
			});
		}
	});
	$("#assign").click(function()
	{
		var sids = new Array();
		var q=$("#projctid").val();
		var pm=$("#proman").val();
		$("input[name='checkp']:checked").each(function(i) {
				sids.push($(this).val());
		});
		var rid = $("#assignto").val();
		if(sids.length == 0)
		{
			alert("Select Phase");
		}
		else
		{
			if(rid == 0)
			{
				alert("Select Resource");
			}
			else
			{
				dataString = "ap=" + sids + "&r=" + rid + "&q=" + q + '&pm=' + pm;
				
				$.ajax
				({
					type: "POST",
					url: "phase.php",
					data: dataString,
					cache: false,
					success: function(html)
					{
					$("#phases").html(html);
					} 
				});
			}
			
		}
		
	});
	$("#addmodule").click(function()
	{
		var sids = new Array();
		var q=$("#projctid").val();
		var pm=$("#proman").val();
		$("input[name='checkp']:checked").each(function(i) {
				sids.push($(this).val());
		});
		var mid = $("#modid").val();
		var dataString = 'msid='+ sids + '&mq='+ q + '&mid=' + mid + '&pm=' + pm;
		if(sids.length == 0)
		{
			alert("Select Phase in which module is to be added");
		}
		else
		{
			if(mid == 0)
			{
				alert("Select Module");
			}
			else
			{
				$.ajax
				({
					type: "POST",
					url: "phase.php",
					data: dataString,
					cache: false,
					success: function(html)
					{
					$("#phases").html(html);
					} 
				});
			}
		}
	});
	
	
	$("#assignm").click(function()
	{
		
		var mids = new Array();
		var q=$("#projctid").val();
		var pm=$("#proman").val();
		
		$("input[name='checkm']:checked").each(function(i) {
				mids.push($(this).val());
		});
		var rid = $("#assignmto").val();
		
		if(mids.length == 0)
		{
			alert("Select Module");
		}
		else
		{
			if(rid == 0)
			{
				alert("Select Resource");
			}
			else
			{
				dataString = "r=" + rid + "&q=" + q + "&mid=" + mids + '&pm=' + pm;
				$.ajax
				({
					type: "POST",
					url: "phase.php",
					data: dataString,
					cache: false,
					success: function(html)
					{
					$("#phases").html(html);
					} 
				});
			}
		}
		
		
	});
});
</script>
	</HEAD>

	<body >
		<?php
			$projectid=$_REQUEST['p'];
			
			$getprojdet=mysql_query("select * from project_master where project_id=$projectid");
			if(mysql_num_rows($getprojdet)>0)
			{
				$projdetres=mysql_fetch_array($getprojdet);
				extract($projdetres);
				$projectName=$project_name;
				$projectDes=$project_description;
				$customer=$project_created_by;
				$createdon=$project_created_on;
				$modifiedon=$project_modified_on;
			}
			$projmng=mysql_query("select * from task_assigned_to a, user_master u where a.project_id=$projectid and a.task_assigned_to=u.user_id and a.role_id=(select role_id from user_roles where role ='Project Manager')");
			if(mysql_num_rows($projmng)>0)
			{
			$promr=mysql_fetch_array($projmng);
			extract($promr);
			$projmanid=$user_id;
			
			$projmanager=$first_name." ".$last_name;
			}
			else
			{
			$projmanid=0;
			$projmanager="Not Assigned";
			}
			$pm = $projmanid;
			echo "<input type='hidden' value='$projmanid' name='proman' id='proman'>";
		?>
		<?php $pageName=$projectName; ?>
		<?php require("includes/header.php"); ?>

		<!-- devi : body content begins here -->

	<!-- <table border='0' cellspacing='0' cellpadding='0' id='loaderContainer' onClick='return false;'>
		<tr><td id='loaderContainerH'><div id='loader'>
			<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td>
				<p><img src='images/wait.gif' height='32' width='32' alt=''/>
				<strong>Please wait.<br>Loading ...</strong></p>
			</td></tr></table>
		</div></td></tr>
	</table> -->
	<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td id='screenH'>
		<div class='pathbar'><a href='index.php'>Admin</a> -> <a href='view-projects.php'>Projects</a> -> <?php echo $projectName;?></div>
		<div class='screenTitle'>
			<table width='100%' cellspacing='0'>
				<tr>
					<td>
						<?php echo $pageName;?>
					</td>		
				</tr>
			</table>
		</div>
<table class="dialog" cellpadding="0" cellspacing="0"><tr><td>
<table class="dialogbox" cellpadding="0" cellspacing="0">
<tr><td>
<!-- icons block area start -->
<p>&nbsp;</p>
<!-- icons block area end -->
<div class="dialoghead" unselectable="on"></div><div class="dialogcontent" unselectable="on">
<!-- dialogcontent start -->

<div class='help' id='helpae' onMouseOut="hMH('ae');">Click here to edit the selected group.</div>
<div class='hide' id='confae'>null</div>
<div class='help' id='helpau' onMouseOut="hMH('au');">Click here to add or remove users to this group.</div>
<div class='hide' id='confau'>null</div>
<div class='help' id='helpaa' onMouseOut="hMH('aa');">Click here to activate the selected group.</div>
<div class='hide' id='confaa'>Are you sure you want to activate the selected group?</div>
<div class='help' id='helpac' onMouseOut="hMH('ac');">Click here to deactivate the selected group.</div>
<div class='hide' id='confac'>Are you sure you want to deactivate the selected group?</div>
<div class='help' id='helpad' onMouseOut="hMH('ad');">Click here to delete the selected group.</div>
<div class='hide' id='confad'>null</div>
<div class='help' id='helpde' onMouseOut="hMH('de');">Click here to edit the selected group.</div>
<div class='hide' id='confde'>null</div>
<div class='listArea'>
<!-- 3D block start -->
<?php if(isset($_SESSION['uid'])) {
?>
<form name='open-project'  method="post" action="open-project-process.php">
<fieldset class="dialogblock">
<legend><span class="textbold" unselectable="on"><?php echo $projectName; ?></span></legend>
		<table width='100%' cellspacing='0' cellpadding='0' border='0'>
			<tr><td>
			<table border='0' width='100%'><tr><td><table border='0' width='70%'>
						<tr><td id='labels'>Project : </td><td><?php echo $projectName;?></td><td width='10%'>&nbsp;</td><td id='labels'>Client : </td><td>
						<?PHP
						$client=mysql_query("select c.* from client_project cp, client_master c where c.client_id=cp.client_id and cp.project_id=$projectid");
						while($clientr=mysql_fetch_array($client))
						{
							echo $clientr['client_name']."<br/>";
						}
						?></td></tr>
						<tr><td id='labels'>Project Manager: </td><td><?php echo $projmanager;?></td><td width='10%'>&nbsp;</td><td id='labels'></td></tr>
						
							<?php $user=mysql_query("select u.* from customer_master u, project_master p where p.project_id=$projectid and u.customer_id=p.project_created_by");
							$userr=mysql_fetch_array($user);
							extract($userr)
							?>
							<tr><td id='labels'>CREATED BY : </td><td><?php echo $userr['customer']; ?></td><td width='10%'>&nbsp;</td><td id='labels'>CREATED ON : </td><td><?php echo $createdon;
							?></td></tr>
							<?php $modifier=mysql_query("select u.* from customer_master u, project_master p where p.project_id=$projectid and u.customer_id=p.project_modified_by");
							if(mysql_num_rows($modifier)>0)
							{
							$modifierr=mysql_fetch_array($modifier);
							extract($modifierr);
							}
							?>
							<tr><td id='labels'>MODIFIED BY : </td><td><?php  
							if(mysql_num_rows($modifier)>0)
							{
							echo $userr['customer'];
							} ?></td><td width='10%'>&nbsp;</td><td id='labels'>MODIFIED ON : </td><td><?php if(mysql_num_rows($modifier)>0)
							{ echo $modifiedon; }?></td></tr>
							
							<tr><td id='labels'>Project Documents : </td><td colspan="4">
							<?php
							$pdoc=mysql_query("select project_doc_id, name from project_doc where project_id=$projectid");
							if(mysql_num_rows($pdoc)>0)
								{
									
									while($pdocr=mysql_fetch_array($pdoc))
									{
										echo "<a href='pdownload.php?id=".$pdocr['project_doc_id']."'>".$pdocr['name']."</a><br/>";
									}
									
								}
								else
								{
									echo "No Files";
								}?></td></tr>
								<tr><td id='labels'>Project Description : </td><td colspan="4"><?php echo $projectDes;?></td></tr>
							</table></td></tr>
							<tr><td>
								<table border='0' width='100%'>
	
								<tr >
									<td class='main'><b>Phases</b></td>
									<td class='misc'>
									<input type='hidden' name='projctid'  value='<?php echo $projectid; ?>' id='projctid'>
									<?php
									
									if($projmanid == $userId || $userType == 'O')
									{
									?>
										<span class="link" >
										
											<SELECT name='phaseid' id='phaseid'>
												<option value='0' Selected='selected'>--Add Phase--</option>
													<?php
													$getphase=mysql_query("select * from phase_master");
													while($getphaser=mysql_fetch_array($getphase))
													{
														echo "<option value='".$getphaser['phase_id']."'>".$getphaser['phase']."</option>";
													}
													?>
											</SELECT>
											
											<input type='button' value='Add Phase' id='addphase'>
											</span>&nbsp;&nbsp;
										<span class="link" >
											<select name='assignto' id='assignto'>
												<option value='0' Selected='selected'>--Assign phase to--</option>
												<?php
												$getusers=mysql_query("select * from user_master where user_created_by=$customerid");
												while($getusersr=mysql_fetch_array($getusers))
												{
												echo "<option value='".$getusersr['user_id']."'>".$getusersr['first_name']." ".$getusersr['last_name']."</option>";
												}

												?>
											</select>
											<input type='submit' value='Assign Phase' name='assign' id='assign'>
										</span>
										<?php
										}
										?>
										
										<span class="link" >
											<SELECT name='modid' id='modid'>
												<option value='' Selected='selected'>--Add Module--</option>
													<?php
													$getmod=mysql_query("select * from module_master");
													while($getmodr=mysql_fetch_array($getmod))
													{
														echo "<option value='".$getmodr['module_id']."'>".$getmodr['module']."</option>";
													}
													?>
											</SELECT>
											
											<input type='submit' value='Add Module' name='addmodule' id='addmodule'>
										</span>
										<span class="link" >
											<select name='assignmto' id='assignmto'>
												<option value='' Selected='selected'>--Assign module to--</option>
												<?php
												$getusers=mysql_query("select * from user_master where user_created_by=$customerid");
												while($getusersr=mysql_fetch_array($getusers))
												{
												echo "<option value='".$getusersr['user_id']."'>".$getusersr['first_name']." ".$getusersr['last_name']."</option>";
												}

												?>
											</select>
											<input type='submit' value='Assign Module' name='assignm' id='assignm'>
									</td></tr>
								</table>
							</td></tr>
							<tr><td id='phases'><?php include('phase.php'); ?></td></tr>
						</table>
			<br/>	
			
			</td></tr>
		</table>
</fieldset>
</form>
<!-- 3D block end -->
</div>


<!-- dialogcontent end -->
</div>
<?php }?>
</td></tr></table>
</td></tr></table>
<p>&nbsp;</p>
	</td></tr></table>

		<!-- devi : body content ends here -->
		
		<?php require("includes/footer.php"); ?>
	</BODY>
</HTML>
